/**
 * Description:
 * Class Name:StringBuilderTest
 * Date:2022/2/19 14:33
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第7章_Java基础类库._7_3_常用类._7_3_3_Java9改进的String_StringBuffer和StringBuilder类;

public class StringBuilderTest {
    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder();
        sb.append("java");                          // "java"
        sb.insert(0, "hello");              // "hellojava"
        sb.replace(5,6,",");            // "hello,java"
        sb.delete(5,6);                             // "hellojava"
        sb.reverse();                               // "avajolleh"
        System.out.println(sb);
        System.out.println(sb.length());
        System.out.println(sb.capacity());
        // 改变长度，将只保留前面部分
        sb.setLength(5);
        System.out.println(sb);
    }
}
